<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="企业id" prop="oldTeamId">
        <el-input
          v-model="queryParams.oldTeamId"
          placeholder="请输入企业id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="关联账号userId" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入关联账号userId"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业名称-必填" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入企业名称-必填"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业简称-必填" prop="shortName">
        <el-input
          v-model="queryParams.shortName"
          placeholder="请输入企业简称-必填"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="管辖区" prop="jurisdiction">
        <el-input
          v-model="queryParams.jurisdiction"
          placeholder="请输入管辖区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业编号-必填" prop="enterpriseNumber">
        <el-input
          v-model="queryParams.enterpriseNumber"
          placeholder="请输入企业编号-必填"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业法人-必填" prop="legalPerson">
        <el-input
          v-model="queryParams.legalPerson"
          placeholder="请输入企业法人-必填"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最大车辆数" prop="maxCarNum">
        <el-input
          v-model="queryParams.maxCarNum"
          placeholder="请输入最大车辆数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车管联系人" prop="vehicleManagementContact">
        <el-input
          v-model="queryParams.vehicleManagementContact"
          placeholder="请输入车管联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车管联系人电话" prop="vehicleManagementContactPhone">
        <el-input
          v-model="queryParams.vehicleManagementContactPhone"
          placeholder="请输入车管联系人电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="道路运输许可证号" prop="roadTransportPermitNumber">
        <el-input
          v-model="queryParams.roadTransportPermitNumber"
          placeholder="请输入道路运输许可证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="建筑垃圾登记证号" prop="constructionWasteRegistrationNumber">
        <el-input
          v-model="queryParams.constructionWasteRegistrationNumber"
          placeholder="请输入建筑垃圾登记证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="有效期至" prop="validUntil">
        <el-date-picker clearable
          v-model="queryParams.validUntil"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择有效期至">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="社会信用代码" prop="socialCreditCode">
        <el-input
          v-model="queryParams.socialCreditCode"
          placeholder="请输入社会信用代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="负责人" prop="pic">
        <el-input
          v-model="queryParams.pic"
          placeholder="请输入负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="负责人电话" prop="picContact">
        <el-input
          v-model="queryParams.picContact"
          placeholder="请输入负责人电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省编号" prop="provinceCode">
        <el-input
          v-model="queryParams.provinceCode"
          placeholder="请输入省编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省名字" prop="provinceName">
        <el-input
          v-model="queryParams.provinceName"
          placeholder="请输入省名字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市编号" prop="cityCode">
        <el-input
          v-model="queryParams.cityCode"
          placeholder="请输入市编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市" prop="cityName">
        <el-input
          v-model="queryParams.cityName"
          placeholder="请输入市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区县编号" prop="areaCode">
        <el-input
          v-model="queryParams.areaCode"
          placeholder="请输入区县编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区/县" prop="areaName">
        <el-input
          v-model="queryParams.areaName"
          placeholder="请输入区/县"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="乡镇名称" prop="townName">
        <el-input
          v-model="queryParams.townName"
          placeholder="请输入乡镇名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="乡镇编码" prop="townCode">
        <el-input
          v-model="queryParams.townCode"
          placeholder="请输入乡镇编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['manger:company:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['manger:company:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['manger:company:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['manger:company:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="companyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="企业id" align="center" prop="oldTeamId" />
      <el-table-column label="关联账号userId" align="center" prop="userId" />
      <el-table-column label="企业名称-必填" align="center" prop="name" />
      <el-table-column label="企业简称-必填" align="center" prop="shortName" />
      <el-table-column label="企业类型" align="center" prop="enterpriseType" />
      <el-table-column label="管辖区" align="center" prop="jurisdiction" />
      <el-table-column label="企业编号-必填" align="center" prop="enterpriseNumber" />
      <el-table-column label="企业法人-必填" align="center" prop="legalPerson" />
      <el-table-column label="最大车辆数" align="center" prop="maxCarNum" />
      <el-table-column label="车管联系人" align="center" prop="vehicleManagementContact" />
      <el-table-column label="车管联系人电话" align="center" prop="vehicleManagementContactPhone" />
      <el-table-column label="道路运输许可证号" align="center" prop="roadTransportPermitNumber" />
      <el-table-column label="建筑垃圾登记证号" align="center" prop="constructionWasteRegistrationNumber" />
      <el-table-column label="有效期至" align="center" prop="validUntil" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.validUntil, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="社会信用代码" align="center" prop="socialCreditCode" />
      <el-table-column label="法人身份证-附件" align="center" prop="legalPersonIdAttachment" />
      <el-table-column label="资质证明-附件" align="center" prop="qualificationCertificateAttachment" />
      <el-table-column label="营业执照-附件" align="center" prop="businessLicenseAttachment" />
      <el-table-column label="其他-附件" align="center" prop="otherAttachment" />
      <el-table-column label="扩展位" align="center" prop="exts" />
      <el-table-column label="企业地址" align="center" prop="address" />
      <el-table-column label="负责人" align="center" prop="pic" />
      <el-table-column label="负责人电话" align="center" prop="picContact" />
      <el-table-column label="备注" align="center" prop="content" />
      <el-table-column label="省编号" align="center" prop="provinceCode" />
      <el-table-column label="省名字" align="center" prop="provinceName" />
      <el-table-column label="市编号" align="center" prop="cityCode" />
      <el-table-column label="市" align="center" prop="cityName" />
      <el-table-column label="区县编号" align="center" prop="areaCode" />
      <el-table-column label="区/县" align="center" prop="areaName" />
      <el-table-column label="乡镇名称" align="center" prop="townName" />
      <el-table-column label="乡镇编码" align="center" prop="townCode" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['manger:company:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['manger:company:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改运输公司信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="企业id" prop="oldTeamId">
          <el-input v-model="form.oldTeamId" placeholder="请输入企业id" />
        </el-form-item>
        <el-form-item label="关联账号userId" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入关联账号userId" />
        </el-form-item>
        <el-form-item label="企业名称-必填" prop="name">
          <el-input v-model="form.name" placeholder="请输入企业名称-必填" />
        </el-form-item>
        <el-form-item label="企业简称-必填" prop="shortName">
          <el-input v-model="form.shortName" placeholder="请输入企业简称-必填" />
        </el-form-item>
        <el-form-item label="管辖区" prop="jurisdiction">
          <el-input v-model="form.jurisdiction" placeholder="请输入管辖区" />
        </el-form-item>
        <el-form-item label="企业编号-必填" prop="enterpriseNumber">
          <el-input v-model="form.enterpriseNumber" placeholder="请输入企业编号-必填" />
        </el-form-item>
        <el-form-item label="企业法人-必填" prop="legalPerson">
          <el-input v-model="form.legalPerson" placeholder="请输入企业法人-必填" />
        </el-form-item>
        <el-form-item label="最大车辆数" prop="maxCarNum">
          <el-input v-model="form.maxCarNum" placeholder="请输入最大车辆数" />
        </el-form-item>
        <el-form-item label="车管联系人" prop="vehicleManagementContact">
          <el-input v-model="form.vehicleManagementContact" placeholder="请输入车管联系人" />
        </el-form-item>
        <el-form-item label="车管联系人电话" prop="vehicleManagementContactPhone">
          <el-input v-model="form.vehicleManagementContactPhone" placeholder="请输入车管联系人电话" />
        </el-form-item>
        <el-form-item label="道路运输许可证号" prop="roadTransportPermitNumber">
          <el-input v-model="form.roadTransportPermitNumber" placeholder="请输入道路运输许可证号" />
        </el-form-item>
        <el-form-item label="建筑垃圾登记证号" prop="constructionWasteRegistrationNumber">
          <el-input v-model="form.constructionWasteRegistrationNumber" placeholder="请输入建筑垃圾登记证号" />
        </el-form-item>
        <el-form-item label="有效期至" prop="validUntil">
          <el-date-picker clearable
            v-model="form.validUntil"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择有效期至">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="社会信用代码" prop="socialCreditCode">
          <el-input v-model="form.socialCreditCode" placeholder="请输入社会信用代码" />
        </el-form-item>
        <el-form-item label="法人身份证-附件" prop="legalPersonIdAttachment">
          <el-input v-model="form.legalPersonIdAttachment" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="资质证明-附件" prop="qualificationCertificateAttachment">
          <el-input v-model="form.qualificationCertificateAttachment" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="营业执照-附件" prop="businessLicenseAttachment">
          <el-input v-model="form.businessLicenseAttachment" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="其他-附件" prop="otherAttachment">
          <el-input v-model="form.otherAttachment" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="扩展位" prop="exts">
          <el-input v-model="form.exts" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="企业地址" prop="address">
          <el-input v-model="form.address" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="负责人" prop="pic">
          <el-input v-model="form.pic" placeholder="请输入负责人" />
        </el-form-item>
        <el-form-item label="负责人电话" prop="picContact">
          <el-input v-model="form.picContact" placeholder="请输入负责人电话" />
        </el-form-item>
        <el-form-item label="备注">
          <editor v-model="form.content" :min-height="192"/>
        </el-form-item>
        <el-form-item label="省编号" prop="provinceCode">
          <el-input v-model="form.provinceCode" placeholder="请输入省编号" />
        </el-form-item>
        <el-form-item label="省名字" prop="provinceName">
          <el-input v-model="form.provinceName" placeholder="请输入省名字" />
        </el-form-item>
        <el-form-item label="市编号" prop="cityCode">
          <el-input v-model="form.cityCode" placeholder="请输入市编号" />
        </el-form-item>
        <el-form-item label="市" prop="cityName">
          <el-input v-model="form.cityName" placeholder="请输入市" />
        </el-form-item>
        <el-form-item label="区县编号" prop="areaCode">
          <el-input v-model="form.areaCode" placeholder="请输入区县编号" />
        </el-form-item>
        <el-form-item label="区/县" prop="areaName">
          <el-input v-model="form.areaName" placeholder="请输入区/县" />
        </el-form-item>
        <el-form-item label="乡镇名称" prop="townName">
          <el-input v-model="form.townName" placeholder="请输入乡镇名称" />
        </el-form-item>
        <el-form-item label="乡镇编码" prop="townCode">
          <el-input v-model="form.townCode" placeholder="请输入乡镇编码" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCompany, getCompany, delCompany, addCompany, updateCompany } from "@/api/manger/company";

export default {
  name: "Company",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 运输公司信息表格数据
      companyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        oldTeamId: null,
        userId: null,
        name: null,
        shortName: null,
        enterpriseType: null,
        jurisdiction: null,
        enterpriseNumber: null,
        legalPerson: null,
        maxCarNum: null,
        vehicleManagementContact: null,
        vehicleManagementContactPhone: null,
        roadTransportPermitNumber: null,
        constructionWasteRegistrationNumber: null,
        validUntil: null,
        socialCreditCode: null,
        legalPersonIdAttachment: null,
        qualificationCertificateAttachment: null,
        businessLicenseAttachment: null,
        otherAttachment: null,
        exts: null,
        address: null,
        pic: null,
        picContact: null,
        content: null,
        provinceCode: null,
        provinceName: null,
        cityCode: null,
        cityName: null,
        areaCode: null,
        areaName: null,
        townName: null,
        townCode: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询运输公司信息列表 */
    getList() {
      this.loading = true;
      listCompany(this.queryParams).then(response => {
        this.companyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        oldTeamId: null,
        userId: null,
        name: null,
        shortName: null,
        enterpriseType: null,
        jurisdiction: null,
        enterpriseNumber: null,
        legalPerson: null,
        maxCarNum: null,
        vehicleManagementContact: null,
        vehicleManagementContactPhone: null,
        roadTransportPermitNumber: null,
        constructionWasteRegistrationNumber: null,
        validUntil: null,
        socialCreditCode: null,
        legalPersonIdAttachment: null,
        qualificationCertificateAttachment: null,
        businessLicenseAttachment: null,
        otherAttachment: null,
        exts: null,
        address: null,
        pic: null,
        picContact: null,
        content: null,
        provinceCode: null,
        provinceName: null,
        cityCode: null,
        cityName: null,
        areaCode: null,
        areaName: null,
        townName: null,
        townCode: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加运输公司信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCompany(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改运输公司信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCompany(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCompany(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除运输公司信息编号为"' + ids + '"的数据项？').then(function() {
        return delCompany(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('manger/company/export', {
        ...this.queryParams
      }, `company_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
